# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=crypto++
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.6.3
pkgrel=3
pkgdesc="Crypto++ Library is a free C++ class library of cryptographic schemes (mingw-w64)"
arch=('any')
url="https://www.cryptopp.com/"
license=('Boost Software License 1.0')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake" "unzip")
source=("https://www.cryptopp.com/cryptopp${pkgver//./}.zip"
        #https://github.com/weidai11/cryptopp/archive/CRYPTOPP_${pkgver//./_}.tar.gz
        libcrypto++.pc
        missing-sources.patch
        cryptopp-cmake.patch
        resolve-namespace-conflict.patch
        fix-test-linking.patch)
sha256sums=('9390670a14170dd0f48a6b6b06f74269ef4b056d4718a1a329f6f6069dc957c9'
            '50abc6e0746de6a8599e7a6b601619a1877bd100788fdb83e74558e9f22adef8'
            'ba5b20cf5335e87f0d33449094a5af8f134bd2222d2d20a18eb4e46135c0d661'
            '43bc272bbbd055628de2a45662ba0fc78a1dde040b07fe06e1979c99cf39137c'
            '6e63acb2b3f76fda56bc7019b3bde4ab7f3ca209310bf4108d21e6c39b7fa0e9'
            '99e5bb3ba211c6155a19a170b7e498b904bf821f7d2aa46be06d08a87846fa17')
noextract=(cryptopp${pkgver//./}.zip)

prepare() {
  cd ${srcdir}
  unzip cryptopp${pkgver//./}.zip -d ${_realname}

  cd ${_realname}
  sed -i -e 's/^CXXFLAGS/#CXXFLAGS/' GNUmakefile
  patch -p1 -i ${srcdir}/missing-sources.patch
  patch -p1 -i ${srcdir}/cryptopp-cmake.patch
  patch -p1 -i ${srcdir}/resolve-namespace-conflict.patch
  patch -p1 -i ${srcdir}/fix-test-linking.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} -j1 install

  install -D -m644 ${srcdir}/${_realname}/License.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
